home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
CHIP Turkiye Ekim 2000.iso
/
prog
/
naps
/
04
/
setup.exe
/
Gnucleus
/
GnuHash.h
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-24
|
2KB
|
70 lines
// GnuHash.h: interface for the CGnuHash class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GNUHASH_H__94D2867A_188C_11D4_ACF2_00A0CC533D52__INCLUDED_)
#define AFX_GNUHASH_H__94D2867A_188C_11D4_ACF2_00A0CC533D52__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Justin Marrese, 5/25/00
// A newer GnuHash based on the old hash by me and John
// The old hash trashed itself when full, losing info on even
// recent connections. This hash has two tables, and switches
// between them when full, so worst case is data stays for the
// lifetime of atleast one table.
// Switching is triggered by having to rehash to often. A bad
// CreateKey function could make this happen alot ... a good
// random function would make the hash table very robust.
//
// Sizes are still hardcoded at this time ... some ugly
// pointer-to-pointer-to-array-of-pointer-of-pointer dynamic memmory
// stuff is holding me back ....
//
// FindValue now returns a pointer to a key_data instead of an index.
// CreateKey now returns a DWORD instead of long.
// Delete is depreciated ... we just wait for the table to fill and then
// destroy it all ... rehashing makes delete extremely complex.
#define HASH_SIZE 10000 // Size of each hash table
#define REHASH_VALUE 13 // Offset for rehashing
#define MAX_REHASH 10 // How many rehashes we try before we consider the current
// table too full, flush the old table, and swap tables.
class CGnuSock;
class CGnuControl;
struct key_data
{
GUID Guid;
CGnuSock *Origin;
};
class CGnuHash
{
public:
CGnuHash();
CGnuHash(CGnuControl *);
virtual ~CGnuHash();
void Insert(GUID *, CGnuSock *);
key_data * FindValue(GUID *);
private:
bool CheckEmpty(int which);
void ClearTable(int which);
DWORD CreateKey(GUID *);
bool CompareGuid(GUID *, GUID *);
key_data *Table[2][HASH_SIZE];
int Current, Old;
int HashEntries;
CGnuControl *GnuComm;
};
#endif // !defined(AFX_GNUHASH_H__94D2867A_188C_11D4_ACF2_00A0CC533D52__INCLUDED_)